package com.tarena.lbs.attach.controller;

import com.tarena.lbs.attach.pojo.vo.FileVO;
import com.tarena.lbs.attach.service.AttachService;
import com.tarena.lbs.base.protocol.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(value = "attach", tags = "附件中心管理")
@Slf4j
@Validated
@RestController
@RequestMapping("attach")
public class AttachController {

    @Resource
    private AttachService attachService;

    @PostMapping("upload")
    @ApiOperation(value = "上传附件")
    public Result<FileVO> uploadAttachInfo(@RequestPart("file") MultipartFile file) throws Exception {
        FileVO fileVO = attachService.uploadAttachInfo(file);
        return new Result<>(fileVO);
    }

}
